package com.weiqiao.api.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.google.gson.Gson;
import com.mongodb.client.model.Filters;
import com.weiqiao.api.domain.VarietyApiEntity;
import com.weiqiao.api.repository.IVarietyApiRepository;
import com.weiqiao.api.service.IVarietyApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ChenYF
 * @Description
 * @Date 2020/7/27 15:13
 */
@Service("VarietyApiServiceImpl")
public class VarietyApiServiceImpl implements IVarietyApiService {

    @Autowired
    private IVarietyApiRepository varietyApiRepository;

    @Override
    public List<VarietyApiEntity> getVarietyList(String company_id) {
        List<VarietyApiEntity> entityList = new ArrayList<>();
        List<String> list = varietyApiRepository.getVarietyList(Filters.eq("company_id", Integer.parseInt(company_id)));
        if (CollectionUtil.isNotEmpty(list)) {
            list.forEach(s -> entityList.add(new Gson().fromJson(s, VarietyApiEntity.class)));
        }
        return entityList;
    }
}
